package com.wd.live.view.fragment;
import android.content.Intent;
import android.view.View;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.GridLayoutManager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.wd.live.R;
import com.wd.live.base.BaseFragment;
import com.wd.live.bean.MineMessageBean;
import com.wd.live.databinding.MyFragmentBinding;
import com.wd.live.view.FansActivity;
import com.wd.live.view.GiftListActivity;
import com.wd.live.view.SiginFragment;
import com.wd.live.view.UserMessageActivity;
import com.wd.live.view.activity.MywalletActivity;
import com.wd.live.viewmodel.MyMessageViewModel;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * <p>项目名称:LookFor2.0</p>
 * <p>包名:com.bawei.lookfor20.view.fragment</p>
 * <p>简述:</p>
 *
 * @author 孟令高
 * @date 2022/11/9
 */
public class MyFragment extends BaseFragment<MyMessageViewModel, MyFragmentBinding> {
    List<String> newList= SiginFragment.newList;
    @Override
    protected void initData() {
        viewmodel.getList().observe(getActivity(), new Observer<MineMessageBean>() {
            @Override
            public void onChanged(MineMessageBean mineMessageBean) {
                MineMessageBean.ResultBean result = mineMessageBean.getResult();
                databind.userName.setText(result.getNickName());
                Glide.with(getActivity())
                        .load(result.getHeadPic())
                        .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                        .into(databind.userImg);
                databind.userQianMing.setText(result.getSignature());
            }
        });
        if(newList!=null && !newList.isEmpty()){
            databind.signrec.setVisibility(View.VISIBLE);
            databind.signrec.setLayoutManager(new GridLayoutManager(getActivity(),newList.size()));
            databind.signrec.setAdapter(new CommonAdapter<String>(getActivity(),R.layout.mysig_item,newList) {

                @Override
                protected void convert(ViewHolder holder, String s, int position) {
                    holder.setText(R.id.sign,s);
                }
            });
        }
        databind.userMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), UserMessageActivity.class));
            }
        });
        databind.mygiftGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), GiftListActivity.class));
            }
        });

        databind.PLikeUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), FansActivity.class));
            }
        });
        databind.mymoneyGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), MywalletActivity.class));
            }
        });
    }

    @Override
    protected int initLayout() {
        return R.layout.my_fragment;
    }

    @Override
    public void onChanged(Object o) {

    }

    @Override
    public void onResume() {
        super.onResume();
        viewmodel.getList().observe(getActivity(), new Observer<MineMessageBean>() {
            @Override
            public void onChanged(MineMessageBean mineMessageBean) {
                MineMessageBean.ResultBean result = mineMessageBean.getResult();
                databind.userName.setText(result.getNickName());
                Glide.with(getActivity())
                        .load(result.getHeadPic())
                        .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                        .into(databind.userImg);
                databind.userQianMing.setText(result.getSignature());
            }
        });
    }
}
